package hw06;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class hw5 {
    public static void main(String[] args) throws IOException {
        String src = "sort.txt";
        BufferedReader br = new BufferedReader(new FileReader(src));
        String line;
        ArrayList<String> list = new ArrayList<>();
        while ((line = br.readLine()) != null) {
            list.add(line);
        }
        br.close();  
        
        Collections.sort(list, new Comparator<String>() {
			public int compare(String o1, String o2) {
				String[] parts1 = o1.split("\\.");
				String[] parts2 = o2.split("\\."); 				
				if (!o1.contains(".") || !o2.contains(".")) {
					return 0;
				}
				int i1 = Integer.parseInt(parts1[0]);
				int i2 = Integer.parseInt(parts2[0]);
				return i1 - i2;
			}
		});

        BufferedWriter bw = new BufferedWriter(new FileWriter("result.txt"));
        for (String str : list) {
            bw.write(str);
            bw.newLine();
        }
        bw.close();
    }
}
